﻿using System;
using System.Collections;
using UnityEngine;
using UnityEngine.Events;

namespace Valve.VR.InteractionSystem
{
	// Token: 0x02000651 RID: 1617
	public class ChaperoneInfo : MonoBehaviour
	{
		// Token: 0x170004ED RID: 1261
		// (get) Token: 0x06002904 RID: 10500 RVA: 0x000EE594 File Offset: 0x000EC794
		// (set) Token: 0x06002905 RID: 10501 RVA: 0x000EE59C File Offset: 0x000EC79C
		public bool initialized { get; private set; }

		// Token: 0x170004EE RID: 1262
		// (get) Token: 0x06002906 RID: 10502 RVA: 0x000EE5A8 File Offset: 0x000EC7A8
		// (set) Token: 0x06002907 RID: 10503 RVA: 0x000EE5B0 File Offset: 0x000EC7B0
		public float playAreaSizeX { get; private set; }

		// Token: 0x170004EF RID: 1263
		// (get) Token: 0x06002908 RID: 10504 RVA: 0x000EE5BC File Offset: 0x000EC7BC
		// (set) Token: 0x06002909 RID: 10505 RVA: 0x000EE5C4 File Offset: 0x000EC7C4
		public float playAreaSizeZ { get; private set; }

		// Token: 0x170004F0 RID: 1264
		// (get) Token: 0x0600290A RID: 10506 RVA: 0x000EE5D0 File Offset: 0x000EC7D0
		// (set) Token: 0x0600290B RID: 10507 RVA: 0x000EE5D8 File Offset: 0x000EC7D8
		public bool roomscale { get; private set; }

		// Token: 0x0600290C RID: 10508 RVA: 0x000EE5E4 File Offset: 0x000EC7E4
		public static SteamVR_Events.Action InitializedAction(UnityAction action)
		{
			return new SteamVR_Events.ActionNoArgs(ChaperoneInfo.Initialized, action);
		}

		// Token: 0x170004F1 RID: 1265
		// (get) Token: 0x0600290D RID: 10509 RVA: 0x000EE5F4 File Offset: 0x000EC7F4
		public static ChaperoneInfo instance
		{
			get
			{
				if (ChaperoneInfo._instance == null)
				{
					ChaperoneInfo._instance = new GameObject("[ChaperoneInfo]").AddComponent<ChaperoneInfo>();
					ChaperoneInfo._instance.initialized = false;
					ChaperoneInfo._instance.playAreaSizeX = 1f;
					ChaperoneInfo._instance.playAreaSizeZ = 1f;
					ChaperoneInfo._instance.roomscale = false;
					UnityEngine.Object.DontDestroyOnLoad(ChaperoneInfo._instance.gameObject);
				}
				return ChaperoneInfo._instance;
			}
		}

		// Token: 0x0600290E RID: 10510 RVA: 0x000EE670 File Offset: 0x000EC870
		private IEnumerator Start()
		{
			CVRChaperone chaperone = OpenVR.Chaperone;
			if (chaperone == null)
			{
				GlobalData.Debug_LogWarning("Failed to get IVRChaperone interface.");
				this.initialized = true;
				yield break;
			}
			float px;
			float pz;
			for (;;)
			{
				px = 0f;
				pz = 0f;
				if (chaperone.GetPlayAreaSize(ref px, ref pz))
				{
					break;
				}
				yield return null;
			}
			this.initialized = true;
			this.playAreaSizeX = px;
			this.playAreaSizeZ = pz;
			this.roomscale = (Mathf.Max(px, pz) > 1.01f);
			Debug.LogFormat("ChaperoneInfo initialized. {2} play area {0:0.00}m x {1:0.00}m", new object[]
			{
				px,
				pz,
				(!this.roomscale) ? "Standing" : "Roomscale"
			});
			ChaperoneInfo.Initialized.Send();
			yield break;
			yield break;
		}

		// Token: 0x04002922 RID: 10530
		public static SteamVR_Events.Event Initialized = new SteamVR_Events.Event();

		// Token: 0x04002923 RID: 10531
		private static ChaperoneInfo _instance;
	}
}
